package com.yxb.config.rest;

public class RestResult {
	
	public static final String CODE_SUCCESS = "00000";
	// 10000 级的是系统通用异常错误
	// 20000 级的是业务异常
	public static final String CODE_ERROR_UNKONWN = "10000";
	public static final String CODE_ERROR_EXCEPTION = "10001";
	public static final String CODE_UNAUTHORIZED = "10002";
	public static final String CODE_PARAM_REQUIRED = "10200";
	public static final String CODE_PARAM_INVALID = "10201";

	public static final String CODE_COMMON_ERROR = "20001";

	private Boolean success;
	private String code;
	private String error;
	private Object data;
	
	public static RestResult success() {
		return RestResult.success(null);
	}
	
	public static RestResult success(Object data) {
		RestResult result = new RestResult();
		result.setSuccess(true);
		result.setCode(CODE_SUCCESS);
		result.setData(data);
		return result;
	}
	
	public static RestResult error(String code, String error) {
		RestResult result = new RestResult();
		result.setSuccess(false);
		result.setCode(code);
		result.setError(error);
		return result;
	}

	public static RestResult commonError( String error) {
		RestResult result = new RestResult();
		result.setSuccess(false);
		result.setCode(CODE_COMMON_ERROR);
		result.setError(error);
		return result;
	}


	public static RestResult errorOfUnkonwn(String error) {
		return RestResult.error(CODE_ERROR_UNKONWN, error);
	}

	public static RestResult errorOfException(String error) {
		return RestResult.error(CODE_ERROR_EXCEPTION, error);
	}

	public static RestResult errorOfParamRequired(String error) {
		return RestResult.error(CODE_PARAM_REQUIRED, error);
	}

	public static RestResult errorOfParamInvalid(String error) {
		return RestResult.error(CODE_PARAM_INVALID, error);
	}
	
	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getError() {
		return error;
	}
	public void setError(String error) {
		this.error = error;
	}
	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
